/**
 * 业务相关类型定义
 * 减少any类型使用，提升类型安全性
 */

import { IBaseResponse, IPaginationParams, IPaginationResponse } from './common';

// BMS 相关类型
export interface IBatteryPack {
  id: string;
  packId: string;
  voltage: number;
  current: number;
  soc: number;
  temperature: number;
  status: number;
  lastUpdateTime: string;
}

export interface IBatteryPackListParams extends IPaginationParams {
  packId?: string;
  status?: number;
  startTime?: string;
  endTime?: string;
}

export interface IBatteryPackListResponse extends IBaseResponse<IPaginationResponse<IBatteryPack>> {}

// 告警相关类型
export interface IAlertItem {
  id: string;
  alertType: string;
  severity: 'low' | 'medium' | 'high' | 'critical';
  message: string;
  deviceId?: string;
  location?: string;
  status: 'active' | 'acknowledged' | 'resolved';
  createTime: string;
  acknowledgeTime?: string;
  resolveTime?: string;
  acknowledgedBy?: string;
  resolvedBy?: string;
}

export interface IAlertListParams extends IPaginationParams {
  alertType?: string;
  severity?: string;
  faultStatus?: number;
  status?: string;
  deviceId?: string;
  startTime?: string;
  endTime?: string;
}

export interface IAlertListResponse extends IBaseResponse<IPaginationResponse<IAlertItem>> {}

// 设备相关类型
export interface IDeviceItem {
  id: string;
  deviceId: string;
  deviceName: string;
  deviceType: string;
  location: string;
  status: number;
  lastOnlineTime: string;
  createTime: string;
}

export interface IDeviceListParams extends IPaginationParams {
  deviceId?: string;
  deviceName?: string;
  deviceType?: string;
  location?: string;
  status?: number;
}

export interface IDeviceListResponse extends IBaseResponse<IPaginationResponse<IDeviceItem>> {}

// 能源统计相关类型
export interface IEnergyData {
  timestamp: string;
  solar: number;
  grid: number;
  battery: number;
  home: number;
  total: number;
}

export interface IEnergyStatisticsParams {
  startTime: string;
  endTime: string;
  interval: 'hour' | 'day' | 'week' | 'month';
}

export interface IEnergyStatisticsResponse extends IBaseResponse<IEnergyData[]> {}

// 系统概览相关类型
export interface ISystemOverview {
  totalDevices: number;
  onlineDevices: number;
  totalAlerts: number;
  activeAlerts: number;
  energyToday: number;
  energyMonth: number;
  systemStatus: 'normal' | 'warning' | 'error';
  lastUpdateTime: string;
}

export interface ISystemOverviewResponse extends IBaseResponse<ISystemOverview> {}

// 报表相关类型
export interface IReportItem {
  id: string;
  reportName: string;
  reportType: string;
  generateTime: string;
  status: 'generating' | 'completed' | 'failed';
  fileUrl?: string;
  fileSize?: number;
  errorMessage?: string;
}

export interface IReportListParams extends IPaginationParams {
  reportName?: string;
  reportType?: string;
  status?: string;
  startTime?: string;
  endTime?: string;
}

export interface IReportListResponse extends IBaseResponse<IPaginationResponse<IReportItem>> {}

// 设置相关类型
export interface ISystemSetting {
  key: string;
  value: string;
  description: string;
  category: string;
  editable: boolean;
  type: 'string' | 'number' | 'boolean' | 'select';
  options?: string[];
}

export interface ISystemSettingResponse extends IBaseResponse<ISystemSetting[]> {}

export interface ISystemSettingUpdate {
  key: string;
  value: string;
}

export interface ISystemSettingUpdateResponse extends IBaseResponse<{
  success: boolean;
  message?: string;
}> {}

// 文件上传相关类型
export interface IFileUploadResponse {
  success: boolean;
  fileUrl?: string;
  fileName?: string;
  fileSize?: number;
  message?: string;
}

// 通用操作响应类型
export interface IOperationResponse {
  success: boolean;
  message: string;
  data?: any;
}

// 数据导出相关类型
export interface IExportParams {
  format: 'excel' | 'csv' | 'pdf';
  filters?: Record<string, any>;
  columns?: string[];
}

export interface IExportResponse {
  success: boolean;
  downloadUrl?: string;
  fileName?: string;
  message?: string;
}

// 数据导入相关类型
export interface IImportParams {
  file: File;
  template?: string;
  options?: Record<string, any>;
}

export interface IImportResponse {
  success: boolean;
  totalRows: number;
  successRows: number;
  failedRows: number;
  errors?: Array<{
    row: number;
    column: string;
    message: string;
  }>;
  message?: string;
}

// 通知相关类型
export interface INotificationItem {
  id: string;
  title: string;
  content: string;
  type: 'info' | 'success' | 'warning' | 'error';
  read: boolean;
  createTime: string;
  readTime?: string;
}

export interface INotificationListParams extends IPaginationParams {
  type?: string;
  read?: boolean;
  startTime?: string;
  endTime?: string;
}

export interface INotificationListResponse extends IBaseResponse<IPaginationResponse<INotificationItem>> {}

// 搜索相关类型
export interface ISearchResult<T = any> {
  items: T[];
  total: number;
  query: string;
  searchTime: number;
}

export interface ISearchParams {
  query: string;
  type?: string;
  filters?: Record<string, any>;
  page?: number;
  pageSize?: number;
}

export interface ISearchResponse<T = any> extends IBaseResponse<ISearchResult<T>> {}
